﻿using System;
using System.Runtime.InteropServices;

namespace VoiceLocal
{
    /// Return Type: int
    ///errorCode: int
    ///param1: int
    ///param2: void*
    ///userData: void*
    public delegate int DownloadStatusCB(int errorCode, int param1, IntPtr param2, IntPtr userData);

    /// Return Type: int
    ///data: void*
    ///dataLen: int
    ///userData: void*
    public delegate int DownloadResultCB(IntPtr data, int dataLen, IntPtr userData);

    /// Return Type: int
    ///sessionID: char*
    ///errorCode: int
    ///status: int
    ///result: void*
    ///rsltLen: int
    ///userData: void*
    public delegate int NLPSearchCB([In] [MarshalAs(UnmanagedType.LPStr)] string sessionID, int errorCode, int status, IntPtr result, int rsltLen, IntPtr userData);

    /// Return Type: void
    ///type: int
    ///status: int
    ///param1: int
    ///param2: void*
    ///userData: void*
    public delegate void msp_status_ntf_handler(int type, int status, int param1, IntPtr param2, IntPtr userData);

    public static class MspDll
    {
        private const string sdk = "msc.dll";
        /// Return Type: char*
        ///wcstr: wchar_t*
        [DllImport(sdk, EntryPoint = "Wchar2Mbytes")]
        public static extern IntPtr Wchar2Mbytes([In] [MarshalAs(UnmanagedType.LPWStr)] string wcstr);


        /// Return Type: wchar_t*
        ///mbstr: char*
        [DllImport(sdk, EntryPoint = "Mbytes2Wchar")]
        public static extern IntPtr Mbytes2Wchar(
            [In,
             MarshalAs(UnmanagedType.LPStr)]
            string mbstr);


        /// Return Type: int
        ///usr: char*
        ///pwd: char*
        ///params: char*
        [DllImport(sdk, EntryPoint = "MSPLogin", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPLogin(
            [In,
             MarshalAs(UnmanagedType.LPStr)]
            string usr, [In] [MarshalAs(UnmanagedType.LPStr)] string pwd, [In] [MarshalAs(UnmanagedType.LPStr)] string @params);


        /// Return Type: int
        ///usr: wchar_t*
        ///pwd: wchar_t*
        ///params: wchar_t*
        [DllImport(sdk, EntryPoint = "MSPLoginW", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPLoginW(
            [In,
             MarshalAs(UnmanagedType.LPWStr)]
            string usr, [In] [MarshalAs(UnmanagedType.LPWStr)] string pwd, [In] [MarshalAs(UnmanagedType.LPWStr)] string @params);


        /// Return Type: int
        [DllImport(sdk, EntryPoint = "MSPLogout", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPLogout();


        /// Return Type: int
        [DllImport(sdk, EntryPoint = "MSPLogoutW", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPLogoutW();


        /// Return Type: int
        ///dataName: char*
        ///params: char*
        ///dataID: char*
        [DllImport(sdk, EntryPoint = "MSPUpload", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPUpload([In] [MarshalAs(UnmanagedType.LPStr)] string dataName, [In] [MarshalAs(UnmanagedType.LPStr)] string @params, [In] [MarshalAs(UnmanagedType.LPStr)] string dataID);


        /// Return Type: int
        ///dataName: char*
        ///params: char*
        ///statusCb: DownloadStatusCB
        ///resultCb: DownloadResultCB
        ///userData: void*
        [DllImport(sdk, EntryPoint = "MSPDownload", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPDownload([In] [MarshalAs(UnmanagedType.LPStr)] string dataName, [In] [MarshalAs(UnmanagedType.LPStr)] string @params, DownloadStatusCB statusCb, DownloadResultCB resultCb, IntPtr userData);


        /// Return Type: int
        ///wdataName: wchar_t*
        ///wparams: wchar_t*
        ///statusCb: DownloadStatusCB
        ///resultCb: DownloadResultCB
        ///userData: void*
        [DllImport(sdk, EntryPoint = "MSPDownloadW", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPDownloadW([In] [MarshalAs(UnmanagedType.LPWStr)] string wdataName, [In] [MarshalAs(UnmanagedType.LPWStr)] string wparams, DownloadStatusCB statusCb, DownloadResultCB resultCb, IntPtr userData);


        /// Return Type: int
        ///data: void*
        ///dataLen: unsigned int
        ///dataStatus: unsigned int
        [DllImport(sdk, EntryPoint = "MSPAppendData", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPAppendData(IntPtr data, uint dataLen, uint dataStatus);


        /// Return Type: char*
        ///rsltLen: unsigned int*
        ///rsltStatus: int*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPGetResult", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPGetResult(ref uint rsltLen, ref int rsltStatus, ref int errorCode);


        /// Return Type: int
        ///paramName: char*
        ///paramValue: char*
        [DllImport(sdk, EntryPoint = "MSPSetParam", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPSetParam([In] [MarshalAs(UnmanagedType.LPStr)] string paramName, [In] [MarshalAs(UnmanagedType.LPStr)] string paramValue);


        /// Return Type: int
        ///paramName: char*
        ///paramValue: char*
        ///valueLen: unsigned int*
        [DllImport(sdk, EntryPoint = "MSPGetParam", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPGetParam([In] [MarshalAs(UnmanagedType.LPStr)] string paramName, IntPtr paramValue, ref uint valueLen);


        /// Return Type: char*
        ///dataName: char*
        ///data: void*
        ///dataLen: unsigned int
        ///params: char*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPUploadData", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPUploadData([In] [MarshalAs(UnmanagedType.LPStr)] string dataName, IntPtr data, uint dataLen, [In] [MarshalAs(UnmanagedType.LPStr)] string @params, ref int errorCode);


        /// Return Type: void*
        ///params: char*
        ///dataLen: unsigned int*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPDownloadData", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPDownloadData([In] [MarshalAs(UnmanagedType.LPStr)] string @params, ref uint dataLen, ref int errorCode);


        /// Return Type: void*
        ///params: wchar_t*
        ///dataLen: unsigned int*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPDownloadDataW", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPDownloadDataW([In] [MarshalAs(UnmanagedType.LPWStr)] string @params, ref uint dataLen, ref int errorCode);


        /// Return Type: char*
        ///params: char*
        ///text: char*
        ///dataLen: unsigned int*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPSearch", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPSearch([In] [MarshalAs(UnmanagedType.LPStr)] string @params, [In] [MarshalAs(UnmanagedType.LPStr)] string text, ref uint dataLen, ref int errorCode);


        /// Return Type: char*
        ///params: char*
        ///text: char*
        ///textLen: unsigned int
        ///errorCode: int*
        ///callback: NLPSearchCB
        ///userData: void*
        [DllImport(sdk, EntryPoint = "MSPNlpSearch", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPNlpSearch([In] [MarshalAs(UnmanagedType.LPStr)] string @params, [In] [MarshalAs(UnmanagedType.LPStr)] string text, uint textLen, ref int errorCode, NLPSearchCB callback, IntPtr userData);


        /// Return Type: int
        ///sessionID: char*
        ///hints: char*
        [DllImport(sdk, EntryPoint = "MSPNlpSchCancel", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPNlpSchCancel([In] [MarshalAs(UnmanagedType.LPStr)] string sessionID, [In] [MarshalAs(UnmanagedType.LPStr)] string hints);


        /// Return Type: int
        ///statusCb: msp_status_ntf_handler
        ///userData: void*
        [DllImport(sdk, EntryPoint = "MSPRegisterNotify", CallingConvention = CallingConvention.StdCall)]
        public static extern int MSPRegisterNotify(msp_status_ntf_handler statusCb, IntPtr userData);


        /// Return Type: char*
        ///verName: char*
        ///errorCode: int*
        [DllImport(sdk, EntryPoint = "MSPGetVersion", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr MSPGetVersion([In] [MarshalAs(UnmanagedType.LPStr)] string verName, ref int errorCode);

    }
}
